package ewa
 
import (
    "fmt"
    "path"
    "strings"
)

const (
    URITYPE_API = 1
    URITYPE_RES = 2
)

func HttpReqPathSuffix(ReqPath string) (int,string) {
    // ReqPath := "/test.html"

    var uri string
     //获取文件名带后缀   [test.html]
    uri = path.Base(ReqPath)
    //fmt.Printf("uri = %s\n", uri)
    

    //获取文件后缀   [.html]
    var fileSuffix string
    fileSuffix = path.Ext(uri) 
    //fmt.Printf("fileSuffix = %s\n", fileSuffix)

    //获取文件名  [test]
    var filenameOnly string
    filenameOnly = strings.TrimSuffix(uri, fileSuffix)
    filenameOnly = filenameOnly
    //fmt.Printf("filenameOnly = %s\n", filenameOnly)
    
    if fileSuffix==".html" || fileSuffix==".htm" {
        if Logoption.Echorequest == "true" {
            l:=fmt.Sprintf("----Echo/> Http request type: URI '%s'", ReqPath)
            Log(l)
        }
        return URITYPE_RES, uri
    }else{
        if Logoption.Echorequest == "true" {
            l:=fmt.Sprintf("----Echo/> Http request type: API '%s'", ReqPath)
            Log(l)
        }
        return URITYPE_API, ReqPath
    }

}